<template>
  <div style="margin-top: 30px;margin-left:200px; width: 700px;">
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
    <el-form-item label="ID" prop="cpId">
        <el-input v-model="ruleForm.cpId" readonly style="width: 80px"></el-input>
      </el-form-item>
      <el-form-item label="公司名称" prop="name">
        <el-input v-model="ruleForm.name" style="width: 300px"></el-input>
      </el-form-item>

      
      <el-form-item label="规模人数" prop="num">
        <el-input v-model="ruleForm.num" style="width: 300px"></el-input>
      </el-form-item>

      <el-form-item label="地址" prop="area">
        <el-input v-model="ruleForm.area" style="width: 600px"></el-input>
      </el-form-item>

      <el-form-item label="创建时间" required>
        <el-col :span="11">
          <el-form-item prop="estTime">
            <el-date-picker  placeholder="选择日期" v-model="ruleForm.estTime"  style="width: 100%;"></el-date-picker>
          </el-form-item>
        </el-col>
      </el-form-item>

      <el-form-item label="公司类型" prop="industryType">
        <el-input v-model="ruleForm.industryType" style="width: 500px"></el-input>
      </el-form-item>

      <el-form-item label="注册资金" prop="regMoney">
        <el-input v-model="ruleForm.regMoney" style="width: 100px"></el-input>
      </el-form-item>

      <el-form-item label="是否上市" prop="license">
        <el-input v-model="ruleForm.license" style="width: 200px"></el-input>
      </el-form-item>
      <el-form-item label="CEO" prop="regName">
        <el-input v-model="ruleForm.regName" style="width: 200px"></el-input>
      </el-form-item>
      <el-form-item label="简介" prop="brief">
        <el-input type="textarea" v-model="ruleForm.brief"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">立即修改</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  category: null,
  data() {
    return {
      ruleForm: {
        name: "",
        num: "",
        estTime: "",
        area: "",
        regMoney: "",
        license: "",
        brief: "",
        regName: "",
        industryType: ""
      },
      rules: {
        name: [{ required: true, message: "请输入公司名称", trigger: "blur" }],
        num:[{ required: true, message: "请输入公司规模", trigger: "blur" }],
        estTime: [{required: true, message: "请选择日期", trigger: "change"}],
        area: [{ required: true, message: "地址", trigger: "blur" }],
        regMoney: [{ required: true, message: "注册资金", trigger: "blur" } ],
        industryType: [{ required: true, message: "类型", trigger: "blur" }],
        regName: [{ required: true, message: "CEO", trigger: "blur" }],
        license: [ {required: true,message: "请输入是否上市",trigger: "blur"},],
        brief: [{ required: true, message: "简介", trigger: "blur" }]}
    };
  },
  methods: {
    handleChange(value) {
      console.log(value);
    },
    submitForm(formName) {
      const _this = this;
      this.$refs[formName].validate(valid => {
        //提交后
         if (valid) {
                        axios.put('http://localhost:8182/company/update',_this.ruleForm).then(function (resp) {
                            if(resp.data.code == 0){
                                _this.$alert(_this.ruleForm.name+'修改成功', '', {
                                    confirmButtonText: '确定',
                                    callback: action => {
                                        _this.$router.push('/companyList')
                                    }
                                });
                            }
                        })
                    }
                });
                },
            
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  },
  //拿后台数据
    created(){
        const _this = this
      axios.get('http://localhost:8182/company/findById/'+_this.$route.query.id).then(function(resp){
        _this.ruleForm=resp.data.data
      })
     /*  alert(_this.$route.query.id)
      console.log(_this.$route.query.id) */
    }
};
</script>
